<%--****************************************************************************
* 文件名：moban.jsp
* 功能： 模板样式
* 版权所有：J126
* 公司名: J126
*
* --时间--               ---作者--- ----------描述----------
* 2016年10月28日 上午9:19:40         杨文晶		                   新建
*****************************************************************************--%>

<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>租户签约</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<!--杨文晶  2016年10月28日 上午9:19:40  js文件导入  start  -->

<!--杨文晶  2016年10月28日 上午9:19:40 js文件导入  end  -->
<!--杨文晶  2016年10月28日 上午9:19:40  css文件导入  start  -->
  <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen"> 
    <link href="../../css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<link href="css/style.css" rel="stylesheet" media="screen">
<!--杨文晶  2016年10月28日 上午9:19:40  css文件导入  end  -->

</head>
<body>
<div style="margin-top:40px" class="container">
<!--杨文晶 2016年10月28日 上午9:19:40  注释  start  -->
<form action="addCompanyPact.do" class="form-horizontal" method="post" id="cbdpactFrom" onsubmit="return checkForm()"  >
	
	<div class="left_div">
	<div class="form-group">
		<label for="pactNO" class="col-sm-4 control-label">合同编号</label>
    	<div class="col-xs-6">
      	<input type="text" class="form-control" id="pactNO" name="pactNO" readonly="readonly" placeholder="合同编号">
    	</div>
 	 </div>
	
	
	 <div class="form-group">
   	 	<label for="companyID" class="col-sm-4 control-label">选择车位</label>
    	<div class="col-xs-6">
     	<select class="form-control" name="comp.companyID" id="companyCarport" >
		</select>
    	</div>
    	<a class="btn btn-info addCartPortBtn"  href="javascript:void(0)"> 增加车位</a>
  </div>
			<div class="form-group">
                <label for="dtp_input2" class="col-sm-4 control-label">合同开始时间</label>
                <div class="input-group date form_datetime col-xs-6" data-date="" data-date-format="yyyy-mm-dd hh:ii" data-link-field="pactStartTime" data-link-format="yyyy-mm-dd hh:ii">
                    <input class="form-control" type="text"  value="" readonly>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
					<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
				<input type="hidden"  id="pactStartTime" name="pactStartTime" value="" /><br/>
            </div>
            <div class="form-group">
                <label for="dtp_input2" class="col-sm-4 control-label">合同截止时间</label>
                <div class="input-group date pactEndTime col-xs-6" data-date="" data-date-format="yyyy-mm-dd hh:ii" data-link-field="pactEndTime" data-link-format="yyyy-mm-dd hh:ii">
                    <input class="form-control" type="text" id="showEndTime" value=""  readonly>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
					<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
                	<input type="hidden" id="pactEndTime" name="pactEndTime" value=""  /><br/>
            </div>
        
	</div>
	<div class="right_div">
		<div class="form-group">
   	 	<label for="companyID" class="col-sm-4 control-label">合同单位</label>
    	<div class="col-xs-6">
     	<select class="form-control" name="comp.companyID" id="companyID" >
		</select>
    	</div>
  </div>
  
	<div class="form-group">
   	 	<label for="companyBoss" class="col-sm-4 control-label">对方联系人</label>
    	<div class="col-xs-6">
      	<input type="text" class="form-control" id="companyBoss" name="comp。companyBoss"  readonly="readonly" placeholder="对方联系人">
    	</div>
  </div>
	<div class="form-group">
   	 	<label for="companyTel" class="col-sm-4 control-label">对方联系人电话</label>
    	<div class="col-xs-6">
      	<input type="text" class="form-control" id="companyTel" name="comp。companyTel"  readonly="readonly" placeholder="对方人联系电话">
    	</div>
  </div>
	
	<div class="form-group">
   	 	<label for="companyTel" class="col-sm-4 control-label">对方单位地址</label>
    	<div class="col-xs-6">
      	<input type="text" class="form-control" id="companyAddress" name="comp。companyAddress" readonly="readonly" placeholder="车位所属单位详细地址">
    	</div>
  </div>
	</div>
   	 	
			<div class="btn_div">
           <input type="submit" class="btn btn-info" name="submit" value="合同新增确定" />

	
</div>


<div id="tablediv">
	<div id="table_topDiv">
	<table class="table table-striped table-bordered table-hover" style="margin:0px;" >

		<thead>
			<tr>
				<th style="width:46px;">编号</th>
				<th style="width:364px;">车位编号</th>
				<th style="width:374px;">车位地址</th>
				<th>操作</th>
			</tr>
		</thead>
	</table>
	</div>
	<div id="table_bottomDiv" style="overflow-y: scroll;height:260px;">
		<table  class="table table-striped table-bordered table-condensed">
		<tbody id="cartportTable">		
		</tbody>
		</table>
	</div>	
</div>
</form>
</div>
<!--杨文晶 2016年10月28日 上午9:19:40  end  -->

<script type="text/javascript" src="jquery/jquery-1.8.3.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/bootstrap-datetimepicker.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="../../js/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>

</body>
<script type="text/javascript">
  
$('.form_datetime').datetimepicker({
    language:  'zh-CN',
    weekStart: 1,
    todayBtn:  1,
	autoclose: 1,
	todayHighlight: 1,
	startView: 2,
	forceParse: 0,
    showMeridian: 1
});
$('.pactEndTime').datetimepicker({
    language:  'zh-CN',
    weekStart: 1,
    todayBtn:  1,
	autoclose: 1,
	todayHighlight: 1,
	startView: 2, 
	forceParse: 0,
    showMeridian: 1
});
var bianhao=0;
var delOption =new Array();
$(function(){
	
		$.ajax({
			url:"initPactNo.do",
			type:"post",
			data:{param:"租字"},
			success:function(msg){
				$("#pactNO").val(msg);
			}
		})
		var carportList ;
	$.ajax({
		url:"findAllCarPort.do",
		type:"post",
		async:false,
		success:function(msg){
			var option ="";
			carportList = msg;
			$.each(msg,function(i,n){
				option+="<option   value='"+n.carportID+"'>车位编号："+n.carportNO+"&nbsp;&nbsp;车位地址:"+n.carportAddress+"</option>"
			})
			$("#companyCarport").append(option);
		}
	})
	
	$(".addCartPortBtn").click(function(){
		var choose =$("#companyCarport").val();
		$.each($("#companyCarport option"),function(i,n){
			if($(n).val()==choose ){
				$(this).remove();
				delOption.push($(this));
			}
		})
		$.each(carportList,function(i,n){
			if(n.carportID==choose){
				bianhao++;
				var table="<tr id='portId"+bianhao+"'><td id='bianhao"+bianhao+"'>"+bianhao+"</td><input type='hidden' name='carprotID' value='"+choose+"'/><td><input type='text' class='form-control  input-sm carNo' name='carportNO' id='carportNO' readonly value='"+n.carportNO+"'/></td><td><input type='text' class='form-control  input-sm carportAddress' readonly id='carportAddress' name='carportAddress' value='"+n.carportAddress+"'/></td><td><button class='btn btn-danger' onclick='delRow("+bianhao+")'>删除</button></td></tr>";
				$("#cartportTable").append(table);
			}
		})
	});	
	
})	
function delRow(obj){
		var del = $("#portId"+obj).children()[1];
		var choose =$(del).val();
		for(var i =0 ;i<delOption.length;i++){
			var v=delOption[i].val();
			if(v==choose){
				$("#companyCarport").append(delOption[i]);
			}
		}
		$("#portId"+obj).remove();
		for(var i=0;i<$("#cartportTable tr").length;i++){
			$("#cartportTable tr td:first-child").eq(i).text(i+1);
		}
		bianhao=bianhao-1;
	}
	
</script>
<script type="text/javascript" src="../../js/jquery-3.1.0.min.js" charset="UTF-8"></script>
<script>
$(function(){
	var companyList ;
	$.ajax({
		url:"getCompany.do",
		type:"post",
		async:false,
		success:function(msg){
			companyList = msg;
			$("#companyBoss").val(msg[0][4]);
			$("#companyTel").val(msg[0][5]);
			$("#companyAddress").val(msg[0][3]);
			var option ="";
			$.each(msg,function(i,n){
				option += "<option   value='"+n[0]+"'>"+n[2]+"</option>";
			})
			$("#companyID").append(option);
		}
	})
	
	$("#companyID").on("change",function(){
		var option = $("#companyID option ");
		var choose = $("#companyID").val();
		for(var i=0;i<companyList.length;i++){
			if(companyList[i][0]==choose){
				$("#companyBoss").val(companyList[i][4]);
				$("#companyTel").val(companyList[i][5]);
				$("#companyAddress").val(companyList[i][3]);
			}
		}
		
	})
})
function checkTime(){
	var pactEndTime = $("#pactEndTime").val();
	var pactStartTime = $("#pactStartTime").val();
	if(pactEndTime=="" || pactStartTime==""){
		alert("你还未选择合约日期");
		return false;
	}else{
		var endTime = pactEndTime.split(" ")[0].split("-");
		var startTime =	pactStartTime .split(" ")[0].split("-");
		var endDate = new Date();
		endDate.setFullYear(endTime[0],endTime[1],endTime[2]);
		var startDate = new Date();
		startDate.setFullYear(startTime[0],startTime[1],startTime[2]);
		if(endDate<startDate || endDate==startDate ){
			alert("合约日期选择错误");
			$("#showEndTime").val("");
			return false;
		}else
			return true;
	}
}
function checkForm(){
	
	var carNo=$("#carportNO").val();
	var carportAddress=$("#carportAddress").val();
	if(!checkTime()){
		return false;
	}
	if(carNo!=undefined && carportAddress!=undefined  ){
		return true;
	}else{
			alert("未选择车位");
			return false;
		}
}

</script>
</html>